package com.example.sso.server.repository;

import com.example.sso.server.entity.User;
import org.springframework.stereotype.Repository;

import javax.annotation.PostConstruct;
import java.util.HashMap;
import java.util.Map;

@Repository
public class UserRepository {

    private final Map<String, User> users = new HashMap<>();

    @PostConstruct
    public void init() {
        users.put("test", new User("test", "123456", "测试用户", "test@test.com"));
        users.put("admin", new User("admin", "admin123", "管理员", "admin@test.com"));
    }

    public User findByUsername(String username) {
        return users.get(username);
    }

    public boolean validateUser(String username, String password) {
        User user = users.get(username);
        return user != null && user.getPassword().equals(password);
    }
}
    